Ext.namespace('VAS');

VAS.DynamicQueryGridWin = function($config) {
	var _this = this;
	var _queryPanel=null;
	var _grid=null;
	var _dynamicFormPanel=null;
	
	_this.items=[];
	//queryPanel
	if (typeof($config.formPanel) == 'object') {
		var queryPanelUrl = $config.formPanel.url;
		var queryPanelId = $config.formPanel.id;
		var queryPanel = new VAS.DynamicItems({
					title : '查询条件',
					url : queryPanelUrl,
					id : queryPanelId,
					border : true,
					height : $config.formPanel.height,
					width : '100%'
				});
		_queryPanel = queryPanel;
		_this.items.push(_queryPanel);
	}
	
	//gridPanel
	if (typeof($config.gridPanel) == 'object') {
		var gridId = "";

		getParams = function(record) {
			var _params = '';
			var fieldName;
			var value;
			var cm = $config.popUp.grid.getColumnModel();
			for (var i = 0; i < cm.getColumnCount(); i++) {
				fieldName = cm.getDataIndex(i);
				value = record.get(fieldName);
				if (fieldName != '') {
					_params = (_params === null || _params == '') ? "?"
							+ fieldName + "=" + value : _params + "&"
							+ fieldName + "=" + value;
				}
			}

			return _params;

		}
//		var params = typeof($config.popUp.record) === 'undefined'
//				? ''
//				: getParams($config.popUp.record);
		var params = '';
		var gridUrl = $config.gridPanel.url + params;
		var gridId = $config.gridPanel.id;
		var gridStoreUrl = $config.gridPanel.storeUrl + params;
		
		var grid = new VAS.CellEditorGrid({
			title : "数据列表",
			id : gridId,
			gridUrl : gridUrl,
			storeUrl : gridStoreUrl,
			rowNumberer : true,
			border : true,
			checkboxSelModel : true,
			sm : new Ext.grid.RowSelectionModel({
						defaults : {
							sortable : true
						}
					}),
			height : $config.gridPanel.height,
			autoScroll : true,
			autoWidth : true,
			page : $config.gridPanel.page,
			lisenters : {},
			popUp : $config.popUp,
			storeId : 'popUp_grid_store_id',
			pageSize : 10
		});
	   _grid=grid;
	   _this.items.push(_grid);
	}
	

	var closeButton = new Ext.Button({
		id : 'close'
		,text : '关闭'
		,handler : function() {
			_this.close();
		}
	});	
	var thisConfig = {
		id:'DynamicQueryGridWin',
		items : _this.items,
		width:$config.width,
		height:$config.height,
		modal:true,
		buttons : [closeButton]
	};

	var _config = $config || {};

	Ext.apply(_this, Ext.apply(_config, thisConfig));
	VAS.DynamicQueryGridWin.superclass.constructor.call(_this);

};

Ext.extend(VAS.DynamicQueryGridWin, VAS.BasicWindow, {});
Ext.reg('dynamicQueryGrid-Win', VAS.DynamicQueryGridWin);